﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace SimJsonRpc
{
    public class RpcHttpServer : IRpcServer
    {
        public void Configure(IApplicationBuilder app)
        {
            app.UseMiddleware<RpcHttpServerMiddleware>();
        }

        void IRpcServer.ConfigureServices<T>(IServiceCollection services, IRpcServerOptions<T> serverOptions)
        {
            if (serverOptions.GetType() != typeof(RpcHttpServerOptions))
            {
                throw new ArgumentException("Options has not supported type");
            }

            services.AddSingleton(serverOptions.GetType(), sp => serverOptions);
        }
    }
}
